package com.zan.config;

import com.zan.interceptor.CheckTokenInterceptor;
import com.zan.interceptor.SetTimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private CheckTokenInterceptor checkTokenInterceptor;

    @Autowired
    private SetTimeInterceptor setTimeInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkTokenInterceptor) //添加拦截器
                //添加拦截规则，则拦截谁，或不拦截谁
                .addPathPatterns("/shopcart/**")
                .addPathPatterns("/userAddr/**")
                .addPathPatterns("/orders/**")
                .addPathPatterns("/user/checkToken");

        registry.addInterceptor(setTimeInterceptor).addPathPatterns("/**"); //对所有的都进行拦截，但都会放行，只是看token是否有值，有值就续命，变成30分钟
    }
}
